//
//  HLTuserchargeViewController.m
//  huiliantong
//
//  Created by hlt on 15/9/22.
//  Copyright © 2015年 hlt. All rights reserved.
//

#import "HLTuserchargeViewController.h"

@interface HLTuserchargeViewController ()<UIWebViewDelegate>




@property (weak, nonatomic) IBOutlet UIWebView *webview;

@property UIAlertView *myAlert;


@end

@implementation HLTuserchargeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
//    Account *acc=[[AccountTool sharedAccountTool] currentAccount];
//    
//    NSString *url=[NSString stringWithFormat:@"%@&user_name=%@",usercharge,acc.custPhone];
//         NSURL *lastURL=[NSURL URLWithString:url];
//        NSMutableURLRequest *newRequest = [NSMutableURLRequest requestWithURL:lastURL];
//    
//        [_webview loadRequest:newRequest];
//    self.webview.delegate=self;
    
    
    //设置返回的按钮的字体的颜色的
    self.navigationController.navigationBar.tintColor=[UIColor whiteColor];
    //设置导航的背景颜色的
    self.navigationController.navigationBar.barTintColor = navigationBarColor;
    //    self.navigationController.title=@"登陆";
//    [self.navigationItem setTitle:@"卡绑定"];
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.extendedLayoutIncludesOpaqueBars = NO;
    self.modalPresentationCapturesStatusBarAppearance = NO;
    
    
    //由于有中文，所以转换url的时候失败了
    _url=[_url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *lastURL=[NSURL URLWithString:_url];
    
    NSMutableURLRequest *newRequest = [NSMutableURLRequest requestWithURL:lastURL];
    
    [_webview loadRequest:newRequest];
    
    self.webview.delegate=self;
    
    
    
    
    
    

    
    
    
}



//开始加载数据
- (void)webViewDidStartLoad:(UIWebView *)webView {
    
    
    if (_myAlert==nil){
        _myAlert = [[UIAlertView alloc] initWithTitle:nil
                                             message: @"正在加载..."
                                            delegate: self
                                   cancelButtonTitle: nil
                                   otherButtonTitles: nil];
        
        UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
        activityView.frame = CGRectMake(120.f, 48.0f, 37.0f, 37.0f);
        [_myAlert addSubview:activityView];
        [activityView startAnimating];
        [_myAlert show];
    }
    
    
    
}










- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    
//     NSURL *lastURL=[NSURL URLWithString:@""];
//    NSMutableURLRequest *newRequest = [NSMutableURLRequest requestWithURL:lastURL];
//    
//    for (NSHTTPCookie *cookie in self.loginCookies)
//    {
//        NSString *cookieString = [NSString stringWithFormat:@"%@=%@", [cookie name], [cookie value]];
//        
//        [newRequest setValue:cookieString forHTTPHeaderField:@"Cookie"];
//        
//        NSLog(@"inserted cookie into request: %@", cookie);
//    } 
//    
//    [webView loadRequest:newRequest];
    
    
    
    
    
    
//    NSDictionary *properties = [[NSMutableDictionary alloc] init];
//    [properties setValue:@"2s2mzx9mfcjentxuahghoj9salnfd8zlcaadd9sdaxc92" forKey:NSHTTPCookieValue];
//    [properties setValue:@"interface_code" forKey:NSHTTPCookieName];
//    [properties setValue:@"" forKey:NSHTTPCookieDomain];
//    [properties setValue:[NSDate dateWithTimeIntervalSinceNow:60*60] forKey:NSHTTPCookieExpires];
//    [properties setValue:@"/" forKey:NSHTTPCookiePath];
//    NSHTTPCookie *cookie = [[NSHTTPCookie alloc] initWithProperties:properties];
//    
//    NSArray *cookies=[NSArray arrayWithObjects:cookie,nil];
//    NSDictionary *headers=[NSHTTPCookie requestHeaderFieldsWithCookies:cookies];
//    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:[@"http://www.hltgz.com/wx/mobile/index.php?m=default&c=InterfaceApp&a=charge&interface_code=2s2mzx9mfcjentxuahghoj9salnfd8zlcaadd9sdaxc92&user_name=18285117540"  valueForKey:@"url"]]];
//    [request setValue:[headers objectForKey:@"Cookie"] forHTTPHeaderField:@"Cookie"];
//    [webView loadRequest:request];
    
    
      [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].style.background='#CCFFFF'"];
    
    [_myAlert dismissWithClickedButtonIndex:0 animated:YES];
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/



- (void)viewWillAppear:(BOOL)animated
{
    
    //设置导航栏不隐藏
//    self.navigationController.navigationBarHidden=NO;
//    self.navigationController.navigationBarHidden = NO;
    
}












@end
